import { searchHotDetail, searchSuggest } from "./../utils/api";
import { defineStore } from "pinia";

type D = {
  order: any[];
  songs: any[];
  albums: any[];
  artists: any[];
  playlists: any[];
};

type S = {
  searchSuggestData: D;
  searchText: string;
  searchHotData: any[];
};

export const useSearchStore = defineStore("search", {
  state: (): S => {
    return {
      searchSuggestData: {
        order: [],
        songs: [],
        albums: [],
        artists: [],
        playlists: [],
      },
      searchText: "",
      searchHotData: [],
    };
  },
  getters: {
    isHot(): boolean {
      return this.searchText === "";
    },
  },
  actions: {
    async actionSearchSuggest(keywords: string) {
      this.searchSuggestData = await searchSuggest(keywords);
    },
    async actionSearchHot() {
      this.searchHotData = await searchHotDetail();
    },
  },
});
